package com.wsapi.core;

import java.util.List;

/**
 * 表示一个模块
 * 
 * @author yangyan
 * 
 */
public class Module {

    // 模块的唯一标识符，尽量的短并且不重复，会作为权限KEY的前缀
    private String id;
    // 模块的名称
    private String name;
    // 模块在程序中的名称,为JS组件类型名称
    private String code;
    // 图标 css class
    private String iconCls;
    // 模块权限
    private List<ModulePermission> permissionList;

    private boolean inited = false;
    private boolean destroyed = false;
    private ModuleInitializer initializer;

    public void init() {
	if (initializer != null && !inited) {
	    initializer.init(this);
	}
	inited = true;
    }

    public void destroy() {
	if (initializer != null && !destroyed) {
	    initializer.destory(this);
	}
	destroyed = true;
    }

    public String getName() {
	return name;
    }

    public void setName(String name) {
	this.name = name;
    }

    public String getId() {
	return id;
    }

    public void setId(String id) {
	this.id = id;
    }

    public String getCode() {
	return code;
    }

    public void setCode(String code) {
	this.code = code;
    }

    public List<ModulePermission> getPermissionList() {
	return permissionList;
    }

    public void setPermissionList(List<ModulePermission> permissionList) {
	this.permissionList = permissionList;
    }

    public static class ModulePermission {
	private String key;
	private String name;

	public String getKey() {
	    return key;
	}

	public String getName() {
	    return name;
	}

	public ModulePermission(String key, String name) {
	    super();
	    this.key = key;
	    this.name = name;
	}
    }

    public String getIconCls() {
	return iconCls;
    }

    public void setIconCls(String iconCls) {
	this.iconCls = iconCls;
    }
}
